package com.tongji.seller.service
{
	import com.tongji.seller.events.GetStoreSavedSceneEvent;
	import com.tongji.seller.model.UserModel;
	
	import flash.system.Security;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.soap.WebService;
	
	import org.robotlegs.mvcs.Actor;
	
	/**
	 * 
	 * @author jiarong
	 * 2011-12-8
	 *
	 */	
	public class AddStoreSceneService extends Actor
	{
		public var ws:WebService;
		
		[Inject]
		public var userModel:UserModel;
		
		public function AddStoreSceneService()
		{
			super();
			ws = new WebService();
			ws.wsdl = "http://share.rryjw.com/VRService.asmx?wsdl";
			ws.useProxy = false;
			ws.loadWSDL();
			Security.loadPolicyFile("http://img.rryjw.com/crossdomain.xml");
		}
		
		/**
		 * 添加店铺用户收藏信息
		 * @param userId
		 * @param scjId
		 * 
		 */		
		public function addStoreFavoriteScene(userId:Number, scjId:Number):void
		{
			ws.AddStoreFavorite(userId, scjId);
			ws.AddStoreFavorite.addEventListener(ResultEvent.RESULT, addStoreUserSceneResult);
			ws.AddStoreFavorite.addEventListener(FaultEvent.FAULT, faultHandler);
		}
				
		/**
		 * 添加店铺用户选择的系统场景
		 * @param userId
		 * @param scjId
		 * 
		 */		
		public function addStoreUserSystemScene(userId:Number,scjId:Array):void
		{
			ws.AddStoreUserSystemScene(scjId, userId);
			ws.AddStoreUserSystemScene.addEventListener(ResultEvent.RESULT, addStoreUserSystemSceneResult);
			ws.AddStoreUserSystemScene.addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		/**
		 * 添加店铺用户最近使用 
		 * @param userId
		 * @param Id
		 * 
		 */		
		public function addStoreRecentOperateScene(userId:Number, Id:Number):void
		{
			ws.AddStoreRecentOperateScene(userId, Id);
			ws.AddStoreRecentOperateScene.addEventListener(ResultEvent.RESULT, addRecentSceneHandler);
			ws.AddStoreRecentOperateScene.addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		private function addStoreUserSceneResult(event:ResultEvent):void
		{
		}				
				
		private function addStoreUserSystemSceneResult(event:ResultEvent):void
		{
			if (event.result == null)
			{
				Alert.show("您选择的场景保存成功");
				dispatch(new GetStoreSavedSceneEvent(GetStoreSavedSceneEvent.GET_SAVED_SCENE, userModel.currentUserID));
			}
		}
		
		private function addRecentSceneHandler(event:ResultEvent):void
		{
			
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show("失败" + event.fault.toString());
		}	
	}
}